#[inline]
fn is_prime(num: u64, primes: &Vec<u64>) -> bool {
    let n = (num as f64).sqrt() as u64;
    primes
        .iter()
        .take_while(|&&p| p <= n)
        .all(|&p| num % p != 0)
}

pub fn goldbach_conjecture() -> u64 {
    let mut odd_composite: u64 = 1;
    let mut primes: Vec<u64> = vec![2];
    let mut count: u8 = 0;
    let mut sum: u64 = 0;
    'outer: while count < 2 {
        odd_composite += 2;
        if is_prime(odd_composite, &primes) {
            primes.push(odd_composite);
        } else {
            for prime in primes[1..].iter().take_while(|&&x| x < odd_composite) {
                let half = (odd_composite - prime) >> 1;
                let sq = (half as f64).sqrt() as u64;
                if sq * sq == half {
                    continue 'outer;
                }
            }
            count += 1;
            sum += odd_composite;
        }
    }
    sum
}
